package com.timoon.webcomponent.utility.helpinfo.cell;

import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import com.timoon.sample.dao.model.InfoMedium;
import com.timoon.webcomponent.utility.helpinfo.HelpInfoService;

/**
 *<p>功能:</p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013</p>
 *<p>Company:sky</p>
 *@author 付乐天
 *@version 1.0 */

public class HelpInfoCellPanel extends Panel {
	
	private HelpInfoService service;

	private String title;
	private Integer infoMediumType;
	
	private Class<? extends WebPage> targetPage;
	
	public HelpInfoCellPanel(String id,String title,Integer infoMediumType,Class<? extends WebPage> targetPage,HelpInfoService service) {
		super(id);
		// TODO Auto-generated constructor stub
		
		this.service=service;
		
		this.targetPage=targetPage;
		
		this.title=title;
		this.infoMediumType=infoMediumType;
		
		renderPanel();
	}

	private void renderPanel() {
		// TODO Auto-generated method stub
		
		renderTitle();
		
		renderList();
	}

	private void renderList() {
		// TODO Auto-generated method stub
		
		List<InfoMedium> infos=this.service.getInfoMediumByType(this.infoMediumType);
		
		ListView<InfoMedium> listView=new ListView<InfoMedium>("wk_list",infos) {
			
			@Override
			protected void populateItem(ListItem<InfoMedium> arg0) {
				// TODO Auto-generated method stub
				
				InfoMedium info=arg0.getModelObject();
				
				PageParameters parameters=new PageParameters();
				parameters.set("info_medium_id", info.getId());
				
				BookmarkablePageLink link=new BookmarkablePageLink<>("wk_link",targetPage,parameters);
				arg0.add(link);
				
				link.add(new Label("wk_label",info.getName()));
				
			}
		};
		
		add(listView);
		
	}

	private void renderTitle() {
		// TODO Auto-generated method stub
		add(new Label("wk_title",this.title));
	}

}
